package com.dingding.service.usermangerservice.impl;

import java.math.BigDecimal;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.bean.databean.response.DataResponse;
import com.dingding.bean.entity.UserLogin;
import com.dingding.bean.entity.Userintegral;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.service.BaseService;
import com.dingding.service.usermangerservice.IUserIntegralService;

/**
 * 
 * @ClassName: UserIntegralServiceImpl 
 * @Description: 用户积分service实现
 * @author cheshaowei
 * @date 2015-10-21 上午10:38:08
 */
public class UserIntegralServiceImpl extends BaseService implements IUserIntegralService{

	private static final Logger log = Logger
			.getLogger(VehicleinfoServiceImpl.class);
	
	@Override
	public void setStatus(DataResponse dataResponse, int status) {
		
	}

	
	/**
	 * @Title: addUserIntegralAccount 
	 * @Description:给全部用户添加用户积分账户表(数据迁移时使用)
	 * @author yuHaiQing
	 * @throws
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
	public boolean addUserIntegralAccount(List<UserLogin> userLogins) {
		
		if(userLogins != null && userLogins.size() > 0){

			for (UserLogin userLogin : userLogins) {
				
				Userintegral userintegral = new Userintegral();
				// 为用户账户表设置主键
				userintegral.setUsId(ToolUtil.getUid());
				// 用户登录ID
				userintegral.setLoginId(userLogin.getUid());
				// 我的积分
				userintegral.setUserIntegral(new BigDecimal(0));
				// 账户状态
				userintegral.setUiStatus(1);
				// 向用户账户表插入一条记录
				try {
					super.userIntegralDao.save(userintegral);
					Thread.sleep(1);
				} catch (Exception e) {
					log.info("给用户添加积分账户时出现异常   类："+this.getClass()+" addUserIntegralAccount()", e);
					return false;
				}
				
			}
			return true;
		}
		
		return false;
	}

}
